/*
-----------------------------------------------------------------------------
Filename:    BaseEngine.h
-----------------------------------------------------------------------------
*/
#ifndef __BaseEngine_h_
#define __BaseEngine_h_

#include <OgreCamera.h>
#include <OgreEntity.h>
#include <OgreLogManager.h>
#include <OgreRoot.h>
#include <OgreViewport.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <OgreConfigFile.h>

#include <OISEvents.h>
#include <OISInputManager.h>
#include <OISKeyboard.h>
#include <OISMouse.h>

#include <SdkTrays.h>
#include <SdkCameraMan.h>

#include "NxOgre.h"
#include "critter.h"
#include "logwriter.h"
#include "Network.h"
#include "PredefinedCameraDescriptions.h"

#include <Windows.h>
#include <shellapi.h>

class BaseEngine : public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener, OgreBites::SdkTrayListener
{
public:
   BaseEngine(void);
    virtual ~BaseEngine(void);

    virtual void go(void);

protected:
    virtual bool setup();
    virtual bool configure(void);
    virtual void chooseSceneManager(void);
    virtual void createCamera(void);
	virtual void giveCameraControlToPlayer(void);
	virtual void cameraFollowPath(Ogre::SceneNode *followNode, std::vector<Ogre::Vector3> path);
    virtual void createFrameListener(void);
    virtual void createScene(void) = 0; 
	virtual void setupPhysics(void) = 0; 
	virtual void stopPhysics(void);
    virtual void destroyScene(void);
    virtual void createViewports(void);
    virtual void setupResources(void);
    virtual void createResourceListener(void);
    virtual void loadResources(void);

    // Ogre::FrameListener
    virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);

    // OIS::KeyListener
    virtual bool keyPressed( const OIS::KeyEvent &arg );
    virtual bool keyReleased( const OIS::KeyEvent &arg );
    // OIS::MouseListener
    virtual bool mouseMoved( const OIS::MouseEvent &arg );
    virtual bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
    virtual bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );

    // Ogre::WindowEventListener
    virtual void windowResized(Ogre::RenderWindow* rw);
    virtual void windowClosed(Ogre::RenderWindow* rw);

    Ogre::Root *mRoot;
	Ogre::SceneNode* camNode;
    Ogre::Camera* mCamera;
	Ogre::AnimationState* mCameraAnimState;
    Ogre::SceneManager* mSceneMgr;
    Ogre::RenderWindow* mWindow;
    Ogre::String mResourcesCfg;
    Ogre::String mPluginsCfg;
	PredefinedCameraDescriptions *mPredefinedCameraDescriptions;


    // OgreBites
    OgreBites::SdkTrayManager* mTrayMgr;
    OgreBites::SdkCameraMan* mCameraMan;     // basic camera controller
    OgreBites::ParamsPanel* mDetailsPanel;   // details panel
    bool mCursorWasVisible;                  // was cursor visible before dialog appeared
    bool mShutDown;


    //OIS Input devices
    OIS::InputManager* mInputManager;
    OIS::Mouse*    mMouse;
    OIS::Keyboard* mKeyboard;

	//System
	DWORD getCurrentTimeScale0(void);
	DWORD getCurrentTimeScale1(void);
	DWORD getCurrentTimeScale2(void);
	bool fileExists(Ogre::String fileName);

	Ogre::String virtual getBenchMarkData(void);
	void virtual resetBenchMarkData(void);

	//Networking
	bool connectToServer(Ogre::String hostAddress, int port);
	bool sendMessageToServer(Ogre::String message);
	Ogre::String receiveMessageFromServer(void);

private:

	//System
	DWORD nLastTick0;
	DWORD nLastTick1;
	DWORD nLastTick2;
	DWORD nCurrentTime;
	DWORD nCurrentTimeScale1;
	DWORD nCurrentTimeScale2;

	//Networking
	Network mNetwork;
};

#endif // #ifndef __BaseEngine_h_
